/**
 * 
 */
package com.dsteiner.xelavos.client;



import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.PaginationWidget;
import com.dsteiner.widgets.client.PrefilledTextArea;
import com.dsteiner.widgets.client.Widgets.ButtonExt;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.IWidget;
import com.dsteiner.widgets.client.Widgets.IWidgetBuilder;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PaginationModel;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.dsteiner.xelavos.client.constants.Constants;
import com.dsteiner.xelavos.client.controller.CommentsController;
import com.dsteiner.xelavos.client.model.AuthenticationModel;
import com.dsteiner.xelavos.client.model.CommentModel;
import com.dsteiner.xelavos.client.model.CommentsModel;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class CommentsWidget extends LazyWidget implements IWidgetBuilder{

	private CommentsController commentsController = new CommentsController();
	private final CommentsModel commentsModel;
	private final AuthenticationModel authenticationModel;

	public CommentsWidget(CommentsModel commentsModel, AuthenticationModel authenticationModel) {
		this.commentsModel = commentsModel;
		this.authenticationModel = authenticationModel;
	}

	@Override
	public Widget createContentWidget() {
		FlowPanel mainPanel = new FlowPanel();
		PrefilledTextBoxModel messageTextBoxModel = new PrefilledTextBoxModel();
		PrefilledTextArea messageTextArea = new PrefilledTextArea(messageTextBoxModel);
		messageTextBoxModel.setDefaultText("escriba su comentario aqui");
		ButtonExt sendButton = new ButtonExt("enviar comentario");
		FlowPanelExt contentPanel = new FlowPanelExt();
		PaginationModel paginationModel = new PaginationModel();
		PaginationWidget paginationWidget = new PaginationWidget(paginationModel);
		
		mainPanel.add(messageTextArea);
		mainPanel.add(sendButton);
		mainPanel.add(contentPanel);
		mainPanel.add(paginationWidget);
		
		messageTextBoxModel.setMaxCount(Constants.MAX_COUNT_STRING);
		
		setStyleName(XelavosResources.INSTANCE.css().commentsWidget());
		messageTextArea.addStyleName(XelavosResources.INSTANCE.css().messageTextArea());

		commentsController.registerCommentsWidget(this);
		commentsController.registerCommentsModel(commentsModel);
		commentsController.registerMessageTextBoxModel(messageTextBoxModel);
		commentsController.registerContentPanel(contentPanel);
		commentsController.registerSendButton(sendButton);
		commentsController.registerIWidgetBuilder(this);
		commentsController.registerJsUtil(JsUtil.getInstance());
		commentsController.registerAuthenticationModel(authenticationModel);
		commentsController.registerPaginationModel(paginationModel);
		
		return mainPanel;
	}

	public IWidget createWidget(Object model) {
		CommentWidget commentsWidget = new CommentWidget((CommentModel) model, authenticationModel);
		return commentsWidget;
	}

}